/*
 * @Author: xiaosihan 
 * @Date: 2021-12-21 19:44:16 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2022-02-11 15:50:05
 */

import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, WebGLRenderer } from "three";
import ApngTexture from "three-base/ApngTexture";
import ringPNG from "./ring.png";

/**
 * 圆环
 */
export default class RingMesh extends Mesh {

    constructor() {
        super(RingMesh.planeGeo);

        this.init();
    }

    static planeGeo = new PlaneGeometry(100, 100, 1, 1);

    static apngTexture = new ApngTexture(ringPNG);

    static frame = 0;

    static isInit = false;

    static material = new MeshBasicMaterial({
        map: RingMesh.apngTexture,
        side: DoubleSide,
        transparent: true,
        alphaTest: 0.05,
    });

    renderOrder = 8;

    init() {
        this.material = RingMesh.material;
        this.rotateX(Math.PI / -2);
    }

    onBeforeRender = (renderer: WebGLRenderer) => {

        const frame = renderer.info.render.frame;

        if (RingMesh.frame !== frame) {
            RingMesh.frame = frame;
            RingMesh.apngTexture.needsUpdate = true;
        }

    }


}